#!/bin/sh


mkdir /root/ins
mv splunkforwarder-7.1.4-5a7a840afcb3-Linux-x86_64.gz /root/ins
cd /root/ins
tar xvf splunkforwarder-7.1.4-5a7a840afcb3-Linux-x86_64.gz
chown -R root:root splunkforwarder/


echo -e "호스트네임을 입력하세요 : c "
read hostname

cd /root/ins/splunkforwarder/etc/system/local
touch inputs.conf
echo "[default]" >> inputs.conf
echo "host=$hostname" >> inputs.conf


touch server.conf
echo "[general]" >> server.conf
echo "serverName=$hostname" >> server.conf

/root/ins/splunkforwarder/bin/splunk btool check

read -s -n1 -p "호스트네임 확인해주세요. 다를 경우 컨트롤+C로 작업취소" keypress


touch limits.conf
echo "[inputproc]" >> limits.conf
echo "max_fd=50" >> limits.conf
echo "[thruput]" >> limits.conf
echo "maxKBps=4097" >> limits.conf

while true
do
		echo "Select:"
		echo "172망은 1번"
		echo "그외 다른 대역대는 2번(NAT IP)"
		echo "1) 172.16.151.130"
		echo "2) 175.114.137.56"
		
		read number
        case $number in
            1)
			  ipaddress1=172.16.151.130
			  ipaddress2=172.16.151.133
              ;break;;
            2)
              ipaddress1=175.114.137.56
			  ipaddress2=175.114.137.61
              ;break;;
            *)
              echo "Error : Unknown Command"
              ;;
            esac
done
			echo $ipaddress1


touch outputs.conf
echo "[tcpout]" >> outputs.conf
echo "defaultGroup = default-autolb-group" >> outputs.conf
echo "[tcpout:default-autolb-group]" >> outputs.conf
echo "server=$ipaddress1:9997" >> outputs.conf
echo "[tcpout-server://$ipaddress1:9997]" >> outputs.conf

cd /root/ins/splunkforwarder/etc
touch instance.cfg
echo "[general]" >> instance.conf
echo "guid=" >> instance.conf

echo "username : admin"
echo "pw : tesst!@#"
read -s -n1 -p "패스워드 확인해주세요. 다음 나오는 readme 후 패스워드 입력 필요" keypress

/root/ins/splunkforwarder/bin/splunk set deploy-poll $ipaddress2:8089
/root/ins/splunkforwarder/bin/splunk enable boot-start
/root/ins/splunkforwarder/bin/splunk enable deploy-client
echo "username : admin"
echo "pw : tesst!@#"
/root/ins/splunkforwarder/bin/splunk start
ps -ef | grep splu

echo 'splunk setup complete!!'
